package meicai.appium.pages.control;

import meicai.appium.engine.TestEngine;
import meicai.appium.engine.TestSuite;
import meicai.appium.pages.model.AllGoodsPage;
import meicai.appium.pages.model.HomePage;
import meicai.appium.utils.Log;

public class PageBaseControl {
	
	public TestEngine engine = TestSuite.getTestEngine();
	
	public AllGoodsPage allGoods;
	public HomePage homePage;
	public Log logger = Log.getLogger(PageBaseControl.class);
	public PageBaseControl() {
		super();
		//logger.debug("pagebasecontrol");
		allGoods = new AllGoodsPage();
		homePage = new HomePage();
	}
	
	public void startApp() {
		engine.startApp();
	}
	
	public void quitApp() {
		for (int i = 0; i < 10; i++) {
			engine.pressBack();
		}
	}
	
	/**
	 * 关闭广告弹窗，优惠券弹窗
	 */
	public void closeAdvertDialog() {
		if(engine.isElementExist(homePage.advertDialog,6)) {
			logger.debug("关闭特别推荐弹窗");
			engine.clickElement(homePage.advertDialogColse);
		}
		
		if(engine.isElementExist(homePage.couponBanner,6)) {
			logger.debug("关闭优惠券弹窗");
			engine.clickElement(homePage.couponBanner);
		}
	}
	
	/**
	 * 第一次打开app, 引导图
	 */
	public void closeAppFirstStartBanner () {
		
		if(!engine.isElementExist(homePage.appFirstStartBanner,6)) {
			return;
		}
		int tryTimes = 6;
		for(int i = 0; i <= tryTimes; i++) {
			if(engine.isElementExist(homePage.appFirstStartBanner)) {
				engine.swipe("left", 5);
			} 
		}
		
		logger.debug("点击 ‘立即体验’");
		
		engine.click(540, 1580);
		
	}
}
